package com.asiainfo.fc.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JLabel;

public class ColorButton extends JLabel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8451742988127131236L;
	private Color c;
	private String text;
	private int defaultWidth = 22;

	public ColorButton(Color c, int number) {
		this.c = c;
		if (number < 10) {
			this.text = " " + number;
		} else {
			this.text = number + "";
		}

		this.setPreferredSize(new Dimension(defaultWidth, defaultWidth));
		this.setBorder(null);
	}

	public void Update(Color c, int number) {
		this.c = c;
		if (number < 10) {
			this.text = " " + number;
		} else {
			this.text = number + "";
		}
		invalidate();
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		g.setColor(c);

		g.fillOval(1, 1, defaultWidth - 1, defaultWidth - 1);
		g.setColor(Color.white);

		int x = 5;
		int y = 16;
		g.drawString(text, x, y);
	}

}
